<template>
  <div class="men-box-top">
    <div class="nav-top-box">
      <img class="logo" src="@/assets/imgs/logo.png" alt />
      <img @click="handShowMen" class="caidan" src="@/assets/imgs/菜单.png" alt />
    </div>
    <transition name="van-slide-down">
      <div v-if="bgAvtive" class="men-list">
        <div class="item" v-for="(item ,index) in navList" :key="index" @click="handNavTo(item)">
          <span class="title">{{item.meta.name}}</span>
          <img class="icon" src="@/assets/imgs/jiantou.png" alt />
        </div>
      </div>
    </transition>
  </div>
</template>
<script>
export default {
  components: {},
  props: {
    bgAvtive: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      showMen: false,
      navList: []
    };
  },
  mounted() {
    this.navList = this.getRoutes();
    console.log(this.getRoutes());
  },
  methods: {
    handNavTo(item) {
      console.log(item);
      if (item.meta.name == "专家培训") {
        window.open("http://h5.cbda1984.com/onStudy");
        return;
      }
      this.$router.push({
        name: item.name
      });
      this.$emit("handNavTo", item);
    },
    handShowMen() {
      this.$emit("handShowMen");
    },
    getRoutes() {
      let routes = this.$router.options.routes;
      console.log(routes);
      let route = new Array();
      routes.forEach(val => {
        if (val.meta.pid === 0) {
          route.push(val);
        }
      });
      return route;
    }
  }
};
</script>
<style lang="less" scoped>
.men-box-top {
  position: relative;
  width: 100%;
  z-index: 99;
  background-color: #fff;
  .men-list {
    width: 100%;
    position: absolute;
    background-color: #fff;
    .item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 0;
      border-bottom: 1px solid #ccc;
      .title {
        color: #333;
        font-size: 13px;
        margin-left: 30px;
        box-sizing: border-box;
      }
      .icon {
        margin-right: 30px;
        box-sizing: border-box;
        width: 13px;
        height: 15px;
      }
    }
  }
  .nav-top-box {
    z-index: 888888;
    padding: 10px 30px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .logo {
      width: 272px;
      height: 30px;
    }
    .caidan {
      width: 19px;
      height: 16px;
    }
  }
}
</style>
